<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="com.houdoudou.bean.*"%>
<% List<Machine> machines= new ArrayList<Machine>(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<%@ include file="validProgrammer.jsp" %>
<link href="<%=request.getContextPath()%>/styles/table.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1 align="center">自提柜管理</h1>    
  
        <form action="<%=request.getContextPath()%>/programmer4Jsp">
    <input type="hidden" name="affair" value="searchMachine" />
    编号： <input type="text" name="id" style="display: inline;" />  
     业主： <input type="text" name="owner" style="display: inline;" />
      模糊： <input type="text" name="search"  style="display: inline;"/> </br/></br/>
     启用： <input type="radio" name="inuse"  value="1"  style="display: inline;" />  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 未启用： <input type="radio" name="inuse"  value="2"  style="display: inline;" />  <br/>
     在线： <input type="radio" name="online" value="1" style="display: inline;" />     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    不在线： <input type="radio" name="online"  value="2" style="display: inline;" /> <br/> 
    故障： <input type="radio" name="failure" value="1" style="display: inline;" />     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    无故障： <input type="radio" name="failure"  value="2" style="display: inline;" /> <br/> 
    <input type="submit" value="搜索"> <br/>
    </form> 
   
<table width="100%" class="tableA">
 <tr>  
 <th width="10%"  style="BACKGROUND-COLOR: #FF0000" >编号</th> 
   <th width="10%" style="BACKGROUND-COLOR: #FF0000"> 业主</th>  
   <th width="10%" style="BACKGROUND-COLOR: #FF0000"> 启用</th>
    <th width="10%" style="BACKGROUND-COLOR: #FF0000"> 在线</th>
      <th width="10%" style="BACKGROUND-COLOR: #FF0000"> 故障</th>
     <th width="10%" style="BACKGROUND-COLOR: #FF0000"  >早班</th> 
      <th width="10%" style="BACKGROUND-COLOR: #FF0000"  >中班</th> 
       <th width="10%" style="BACKGROUND-COLOR: #FF0000"  >晚班</th> 
        <th width="20%" style="BACKGROUND-COLOR: #FF0000"  >操作</th> 
     </tr> 
<%!   String  caculateUse(String tag ){  
             String result="";           
            if(tag.equals("1")) result="启用";
             if(tag.equals("2")) result="未启用";
              if(tag.equals("0")) result="未定义";
            return result;
             }     %>
<%!   String  caculateTemp(String tag ){          
            String result="";           
            if(tag.equals("1")) result="常温";
             if(tag.equals("2")) result="加热";
              if(tag.equals("3")) result="制冷";
              if(tag.equals("0")) result="未定义";
            return result;
             }     %>
<%!String morning="未处理",noon="未处理",evening="未处理", inuse="未加载",failure="未加载",online="未加载";  %>
 <% boolean success; 
    Object temp =request.getAttribute("success");
     if(temp==null){
     success=false;
     }else{
       success= (Boolean) temp;
     }
    if(success) {
               request.removeAttribute("success");
     machines= ( List<Machine>) request.getSession().getAttribute("machines"); }
    
   
        for (int i = 0; i < machines.size(); i++) {     
             pageContext.setAttribute("machine", machines.get(i));  
             
             String timeCfg=machines.get(i).getTimeCfg(); 
              String tempCfg=machines.get(i).getTempCfg(); 
             if((!timeCfg.isEmpty())&&(!tempCfg.isEmpty())){
             
            morning=  caculateTemp(tempCfg.substring(0, 1))+caculateUse(timeCfg.substring(0, 1));
             noon=  caculateTemp(tempCfg.substring(1, 2))+caculateUse(timeCfg.substring(1, 2)); 
             evening=caculateTemp(tempCfg.substring(2, 3))+caculateUse(timeCfg.substring(2, 3)); 
             if(machines.get(i).getOnline()==1) online="在线";
             if(machines.get(i).getOnline()!=1) online="不在线";
             if(machines.get(i).getFailure()==1) failure="故障";
             if(machines.get(i).getFailure()!=1) failure="没故障";
              if(machines.get(i).getInuse()==1) inuse="使用中";
              if(machines.get(i).getInuse()!=1) inuse="没使用";
            pageContext.setAttribute("morning",morning);
             pageContext.setAttribute("noon",noon);
              pageContext.setAttribute("evening",evening); 
                pageContext.setAttribute("row", i % 2 != 0 ? "odd" : "even");} %>           
                       <tr>           
                                    <td>${machine.id}</td>               
                                    <td>${machine.owner}</td>    
                                    <td><%=inuse %></td>        
                                    <td><%=online %></td>  
                                      <td><%=failure %></td>             
                                    <td><%=morning %></td>  
                                     <td><%=noon %></td>     
                                     <td><%=evening %></td>    
                       <td><a href="<%=request.getContextPath()%>/programmer4Jsp?affair=modifyMachine&id=${machine.id}">修改</a> |
                        <a href="<%=request.getContextPath()%>/programmer4Jsp?affair=detailMachine&id=${machine.id}">详情</a>  |
                        <a href="<%=request.getContextPath()%>/programmer4Jsp?affair=deleteMachine&id=${machine.id}">删除</a></td>           
                             </tr> 
<%} %>
  
 </table>  
 <br/>   <br/>   <br/>  
</body>
</html>
<script> 
//取出传回来的参数error并与yes比较
  var errorInfoA ='<%=request.getParameter("errorInfo")%>';
  var  errorInfo=decodeURI(errorInfoA);
  if(errorInfo!='null'){
   alert(errorInfo);}

</script>